
//登录校验
function denglu(){
	var username = document.getElementById("username").value;
	var password = document.getElementById("password").value;
	var wy = document.getElementsByName("wy");
	var yonghu;
    for(var i=0;i<wy.length;i++){
        if(wy[i].checked){
           yonghu = wy[i].value;
        }
    }
    if(username == "" || password == ""){
        alert("用户名或者密码不能为空");
        return false;
    }else{
        if(yonghu == null){
            alert("请选择你的权限");
        }else{
            doAjax(yonghu+"/denglu?username="+username+"&password="+password);
        }
    }
}
//重置功能
function chongzhi(){
    var username = document.getElementById("username");
    var password = document.getElementById("password");
    var wy = document.getElementsByName("wy");
    username.value = "";
    password.value = "";
    for(var i=0;i<wy.length;i++){
        wy[i].checked = false;
    }
}

var xmlhttp;
function createXMLHttpRequest(){
	xmlhttp = new XMLHttpRequest();
	if(xmlhttp.overrideMimeType){
		xmlhttp.overrideMimeType("text/xml");
	}
}
function doAjax(url){
	createXMLHttpRequest();
	if(xmlhttp != null){
		xmlhttp.onreadystatechange = processRequest;
		xmlhttp.open("post",url,true,"","");
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send(null);
	}else {
		alert("XMLHttpRequest对象未初始化!");
	}
}
function processRequest(){
	if(xmlhttp.readyState == 4){
		if(xmlhttp.status == 200){
			var jieguo = xmlhttp.responseText;
            if(jieguo != "登录失败"){
                alert("登录成功");
                location.href = jieguo;
            }else{
                alert(jieguo);
            }
		}else{
			alert("校严用户名Ajax请求未正常放回!\nError:"+xmlhttp.status+""+xmlhttp.statusText);
		}
	}
}